package exercise.bingfa;

import java.util.concurrent.atomic.AtomicLong;

public class ThreadLearn {
    public static AtomicLong result=new AtomicLong() ;
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 10000; i++) {
            MyThread myThread = new MyThread(100);
            Thread thread = new Thread(myThread);
            thread.start();
        }
        Thread.sleep(10*1000);
        System.out.println(result);
    }

}
class MyThread implements Runnable {
    private int count;
    public MyThread(int count) {
        this.count = count;
    }
    @Override
    public void run() {
        int sum = 0;
        for (int i = 0; i <= count; i++) {
            sum+=i;
        }
        ThreadLearn.result.addAndGet(sum);
        System.out.println(sum);
    }
    //三种，这是第一种，第二种是join写法，第三种是用锁
}
